package Presentacion;

import AccesoDatos.Comando;
import AccesoDatos.Conexion;
import LogicaNegocio.Deuda;
import LogicaNegocio.Promesa;
import LogicaNegocio.Telefono;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Cris
 */
public class frmGestionCobro extends javax.swing.JInternalFrame {

    Conexion conexion = null;
    Deuda deuda = new Deuda();
    Vector<Object> Vgestiones = new Vector<Object>(1,1); // Vector para guardar todas las gestiones asociadas a una deuda, va a ser util para el "popup" para poder visualizar las gestiones en una nueva ventana
    Promesa promesa = null;
    ArrayList <Telefono> vTelefonos = new ArrayList <Telefono>();
    
    public frmGestionCobro(Conexion Pconexion, Deuda Pdeuda) {
        conexion = Pconexion;
        deuda = Pdeuda;
        vTelefonos = Pdeuda.getDeudor().getvTelefonos();
        initComponents();
        cargarDeuda();//Metodo que carga los datos de la deuda en los campos de texto
        cargarTbHistorialGestiones(); //Metodo que carga todas las gestiones que tiene la deuda
        cargarTbPromesas();//Metodo que carga las promesas que tiene la deuda
//        tbHistorialGestiones.getColumnModel().getColumn(0).setPreferredWidth(5);
//        tbHistorialGestiones.getColumnModel().getColumn(1).setPreferredWidth(200);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btngPeriodo = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanelDeudor = new javax.swing.JPanel();
        lbCedula = new javax.swing.JLabel();
        lbNombre = new javax.swing.JLabel();
        lbEmail = new javax.swing.JLabel();
        lbTelLocalizado = new javax.swing.JLabel();
        lbTelefono = new javax.swing.JLabel();
        lbTelefonos = new javax.swing.JLabel();
        txtCedula = new javax.swing.JTextField();
        txtNombre = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        txtTelLocalizado = new javax.swing.JTextField();
        txtTelefono = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtaTelefonos = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jPanelDetalleDeuda = new javax.swing.JPanel();
        lbNumeroOperacion = new javax.swing.JLabel();
        txtOperacion = new javax.swing.JTextField();
        lbDiasMora = new javax.swing.JLabel();
        txtDiasMora = new javax.swing.JTextField();
        lbCapital = new javax.swing.JLabel();
        lbCuota = new javax.swing.JLabel();
        lbSaldo = new javax.swing.JLabel();
        lbTotalAdeudado = new javax.swing.JLabel();
        lbPagoMinimo = new javax.swing.JLabel();
        lbUltimoPago = new javax.swing.JLabel();
        lbProximoPago = new javax.swing.JLabel();
        lbMontoPagado = new javax.swing.JLabel();
        lbTipoProducto = new javax.swing.JLabel();
        txtCapital = new javax.swing.JTextField();
        txtCouta = new javax.swing.JTextField();
        txtSaldo = new javax.swing.JTextField();
        txtTotalAdeudado = new javax.swing.JTextField();
        txtPagoMinimo = new javax.swing.JTextField();
        txtUltimoPago = new javax.swing.JTextField();
        txtProximoPago = new javax.swing.JTextField();
        txtMontoPagado = new javax.swing.JTextField();
        txtTipoProducto = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jPanelPromesaPago = new javax.swing.JPanel();
        lbFechaPromesa = new javax.swing.JLabel();
        dcFechaPromesa = new com.toedter.calendar.JDateChooser();
        lbMontoPromesa = new javax.swing.JLabel();
        txtMontoPromesa = new javax.swing.JTextField();
        rbSemanal = new javax.swing.JRadioButton();
        rbQuincenal = new javax.swing.JRadioButton();
        rbMensual = new javax.swing.JRadioButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        tbPromesas = new javax.swing.JTable();
        jCheckBox2 = new javax.swing.JCheckBox();
        jPanelGestionCobro2 = new javax.swing.JPanel();
        cbLocalizado2 = new javax.swing.JCheckBox();
        dcFechaGestion = new com.toedter.calendar.JDateChooser();
        lbFechaGestion = new javax.swing.JLabel();
        lbTipo = new javax.swing.JLabel();
        cbTipo = new javax.swing.JComboBox();
        lbGestion = new javax.swing.JLabel();
        jScrollPane9 = new javax.swing.JScrollPane();
        txtArGestion = new javax.swing.JTextArea();
        dcFechaProximaGestion = new com.toedter.calendar.JDateChooser();
        lbProximaGestion = new javax.swing.JLabel();
        lbObservaciones = new javax.swing.JLabel();
        jScrollPane10 = new javax.swing.JScrollPane();
        txtArObservaciones = new javax.swing.JTextArea();
        lbEnvioCartas = new javax.swing.JLabel();
        chbEnvioCartas = new javax.swing.JCheckBox();
        btnPatrono = new javax.swing.JButton();
        btnDirecciones = new javax.swing.JButton();
        btnPagos = new javax.swing.JButton();
        lbHistorialGestiones = new javax.swing.JLabel();
        jScrollPane11 = new javax.swing.JScrollPane();
        tbHistorialGestiones = new javax.swing.JTable();
        btnGuardar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Gestión de Cobro");

        jTabbedPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jTabbedPane1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        lbCedula.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbCedula.setText("Cédula");

        lbNombre.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbNombre.setText("Nombre");

        lbEmail.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbEmail.setText("E-mail");

        lbTelLocalizado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbTelLocalizado.setText("Teléfono localizado");

        lbTelefono.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbTelefono.setText("Télefono");
        lbTelefono.setToolTipText("");

        lbTelefonos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbTelefonos.setText("Teléfonos");

        txtCedula.setEditable(false);
        txtCedula.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        txtNombre.setEditable(false);
        txtNombre.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        txtEmail.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        txtTelLocalizado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        txtTelefono.setEditable(false);
        txtTelefono.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jScrollPane1.setHorizontalScrollBar(null);

        txtaTelefonos.setEditable(false);
        txtaTelefonos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtaTelefonos.setLineWrap(true);
        txtaTelefonos.setRows(3);
        txtaTelefonos.setTabSize(2);
        jScrollPane1.setViewportView(txtaTelefonos);

        javax.swing.GroupLayout jPanelDeudorLayout = new javax.swing.GroupLayout(jPanelDeudor);
        jPanelDeudor.setLayout(jPanelDeudorLayout);
        jPanelDeudorLayout.setHorizontalGroup(
            jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDeudorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbTelLocalizado)
                    .addComponent(lbTelefono)
                    .addComponent(lbTelefonos)
                    .addComponent(lbCedula)
                    .addComponent(lbNombre)
                    .addComponent(lbEmail))
                .addGap(18, 18, 18)
                .addGroup(jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNombre)
                    .addComponent(txtCedula, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtTelLocalizado)
                    .addComponent(txtEmail, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanelDeudorLayout.setVerticalGroup(
            jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDeudorLayout.createSequentialGroup()
                .addGroup(jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCedula)
                    .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNombre)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTelLocalizado)
                    .addComponent(txtTelLocalizado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTelefono)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelDeudorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbTelefonos)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 38, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelDeudor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jPanelDeudor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(115, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Datos del Deudor", jPanel1);

        lbNumeroOperacion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbNumeroOperacion.setText("Número de operación");

        txtOperacion.setEditable(false);
        txtOperacion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtOperacion.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtOperacionPropertyChange(evt);
            }
        });

        lbDiasMora.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbDiasMora.setText("Días mora");

        txtDiasMora.setEditable(false);
        txtDiasMora.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtDiasMora.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtDiasMoraPropertyChange(evt);
            }
        });

        lbCapital.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbCapital.setText("Capital");

        lbCuota.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbCuota.setText("Cuota");

        lbSaldo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbSaldo.setText("Saldo");

        lbTotalAdeudado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbTotalAdeudado.setText("Total adeudado");

        lbPagoMinimo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbPagoMinimo.setText("Pago mínimo");

        lbUltimoPago.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbUltimoPago.setText("Último pago");

        lbProximoPago.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbProximoPago.setText("Próximo Pago");

        lbMontoPagado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbMontoPagado.setText("Monto pagado");

        lbTipoProducto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbTipoProducto.setText("Tipo de producto");

        txtCapital.setEditable(false);
        txtCapital.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtCapital.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtCapitalPropertyChange(evt);
            }
        });

        txtCouta.setEditable(false);
        txtCouta.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtCouta.setText("₡");
        txtCouta.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtCoutaPropertyChange(evt);
            }
        });

        txtSaldo.setEditable(false);
        txtSaldo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtSaldo.setText("₡");
        txtSaldo.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtSaldoPropertyChange(evt);
            }
        });

        txtTotalAdeudado.setEditable(false);
        txtTotalAdeudado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtTotalAdeudado.setText("₡");
        txtTotalAdeudado.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtTotalAdeudadoPropertyChange(evt);
            }
        });

        txtPagoMinimo.setEditable(false);
        txtPagoMinimo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtPagoMinimo.setText("₡");
        txtPagoMinimo.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtPagoMinimoPropertyChange(evt);
            }
        });

        txtUltimoPago.setEditable(false);
        txtUltimoPago.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtUltimoPago.setToolTipText("");
        txtUltimoPago.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtUltimoPagoPropertyChange(evt);
            }
        });

        txtProximoPago.setEditable(false);
        txtProximoPago.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtProximoPago.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtProximoPagoPropertyChange(evt);
            }
        });

        txtMontoPagado.setEditable(false);
        txtMontoPagado.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtMontoPagado.setText("₡");
        txtMontoPagado.setToolTipText("");
        txtMontoPagado.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtMontoPagadoPropertyChange(evt);
            }
        });

        txtTipoProducto.setEditable(false);
        txtTipoProducto.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        txtTipoProducto.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTipoProducto.setToolTipText("");
        txtTipoProducto.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtTipoProductoPropertyChange(evt);
            }
        });

        javax.swing.GroupLayout jPanelDetalleDeudaLayout = new javax.swing.GroupLayout(jPanelDetalleDeuda);
        jPanelDetalleDeuda.setLayout(jPanelDetalleDeudaLayout);
        jPanelDetalleDeudaLayout.setHorizontalGroup(
            jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDetalleDeudaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbNumeroOperacion)
                    .addComponent(lbDiasMora)
                    .addComponent(lbCapital)
                    .addComponent(lbCuota)
                    .addComponent(lbSaldo)
                    .addComponent(lbTotalAdeudado)
                    .addComponent(lbPagoMinimo)
                    .addComponent(lbUltimoPago)
                    .addComponent(lbProximoPago)
                    .addComponent(lbMontoPagado)
                    .addComponent(lbTipoProducto))
                .addGap(18, 18, 18)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtTotalAdeudado, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
                    .addComponent(txtPagoMinimo)
                    .addComponent(txtUltimoPago)
                    .addComponent(txtProximoPago)
                    .addComponent(txtMontoPagado)
                    .addComponent(txtSaldo, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtTipoProducto, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtCouta)
                    .addComponent(txtCapital)
                    .addComponent(txtDiasMora)
                    .addComponent(txtOperacion))
                .addGap(45, 45, 45))
        );
        jPanelDetalleDeudaLayout.setVerticalGroup(
            jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDetalleDeudaLayout.createSequentialGroup()
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNumeroOperacion)
                    .addComponent(txtOperacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbDiasMora)
                    .addComponent(txtDiasMora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCapital)
                    .addComponent(txtCapital, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCuota)
                    .addComponent(txtCouta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbSaldo)
                    .addComponent(txtSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTotalAdeudado)
                    .addComponent(txtTotalAdeudado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbPagoMinimo)
                    .addComponent(txtPagoMinimo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbUltimoPago)
                    .addComponent(txtUltimoPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbProximoPago)
                    .addComponent(txtProximoPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbMontoPagado)
                    .addComponent(txtMontoPagado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDetalleDeudaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTipoProducto)
                    .addComponent(txtTipoProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 20, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelDetalleDeuda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jPanelDetalleDeuda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(50, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Detalle de la deuda", jPanel2);

        lbFechaPromesa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbFechaPromesa.setText("Fecha de promesa");

        dcFechaPromesa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        lbMontoPromesa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbMontoPromesa.setText("Monto de la promesa");

        txtMontoPromesa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        btngPeriodo.add(rbSemanal);
        rbSemanal.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rbSemanal.setText("Semanal");

        btngPeriodo.add(rbQuincenal);
        rbQuincenal.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rbQuincenal.setText("Quincenal");

        btngPeriodo.add(rbMensual);
        rbMensual.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        rbMensual.setText("Mensual");

        tbPromesas.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        tbPromesas.setToolTipText("");
        jScrollPane5.setViewportView(tbPromesas);

        jCheckBox2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jCheckBox2.setText("Promesa incumplida");
        jCheckBox2.setToolTipText("Se marca si la promesa ha sido incumplida en la fecha establecida");
        jCheckBox2.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);

        javax.swing.GroupLayout jPanelPromesaPagoLayout = new javax.swing.GroupLayout(jPanelPromesaPago);
        jPanelPromesaPago.setLayout(jPanelPromesaPagoLayout);
        jPanelPromesaPagoLayout.setHorizontalGroup(
            jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPromesaPagoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelPromesaPagoLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(rbSemanal)
                        .addGap(18, 18, 18)
                        .addComponent(rbQuincenal)
                        .addGap(18, 18, 18)
                        .addComponent(rbMensual)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanelPromesaPagoLayout.createSequentialGroup()
                        .addGroup(jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addGroup(jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jCheckBox2)
                                .addGroup(jPanelPromesaPagoLayout.createSequentialGroup()
                                    .addGroup(jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lbFechaPromesa)
                                        .addComponent(lbMontoPromesa))
                                    .addGroup(jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(jPanelPromesaPagoLayout.createSequentialGroup()
                                            .addGap(19, 19, 19)
                                            .addComponent(dcFechaPromesa, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanelPromesaPagoLayout.createSequentialGroup()
                                            .addGap(18, 18, 18)
                                            .addComponent(txtMontoPromesa))))))
                        .addGap(0, 43, Short.MAX_VALUE))))
        );
        jPanelPromesaPagoLayout.setVerticalGroup(
            jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPromesaPagoLayout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addGroup(jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dcFechaPromesa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbFechaPromesa))
                .addGap(18, 18, 18)
                .addGroup(jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbMontoPromesa)
                    .addComponent(txtMontoPromesa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelPromesaPagoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbSemanal)
                    .addComponent(rbQuincenal)
                    .addComponent(rbMensual))
                .addGap(18, 18, 18)
                .addComponent(jCheckBox2)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelPromesaPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(62, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jPanelPromesaPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(95, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Promesa de pago", jPanel3);

        jPanelGestionCobro2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Gestión de cobro", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 0, 14))); // NOI18N
        jPanelGestionCobro2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        cbLocalizado2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbLocalizado2.setText("Deudor localizado");
        cbLocalizado2.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);

        dcFechaGestion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        lbFechaGestion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbFechaGestion.setText("Fecha de gestión");

        lbTipo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbTipo.setText("Tipo");

        cbTipo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        cbTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "...", "AD Cuenta al día", "CC Cuenta cancelada", "CJ Cobro judicial", "DL Deudor localizado", "F fallecido", "IL Ilocalizable", "INC Incobrable", "IP Incumplimiento de pago", "NC Cliente No Contesta", "NPP No puede pagar", "NQP No quiere pagar", "PAP Posible arreglo de pago", "PI Promesa incumplida", "PP Pago parcial", "PRP Promesa de pago", "RCA Recado en casa del cliente", "RCEL Recado en celular del cliente", "RT Recado en el trabajo del cliente", "TF Trámite de finiquito", "VC Se visitó en la casa", "VT Se visitó al trabajo" }));

        lbGestion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbGestion.setText("Gestión");

        txtArGestion.setColumns(20);
        txtArGestion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtArGestion.setRows(5);
        jScrollPane9.setViewportView(txtArGestion);

        dcFechaProximaGestion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        lbProximaGestion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbProximaGestion.setText("Próxima gestión");

        lbObservaciones.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbObservaciones.setText("Observaciones");

        txtArObservaciones.setColumns(20);
        txtArObservaciones.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtArObservaciones.setRows(5);
        jScrollPane10.setViewportView(txtArObservaciones);

        lbEnvioCartas.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbEnvioCartas.setText("Envío de cartas");

        btnPatrono.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnPatrono.setText("Patrono");

        btnDirecciones.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnDirecciones.setText("Direcciones");

        btnPagos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnPagos.setText("Pagos");

        lbHistorialGestiones.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbHistorialGestiones.setText("Historial de gestiones");

        tbHistorialGestiones.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jScrollPane11.setViewportView(tbHistorialGestiones);

        javax.swing.GroupLayout jPanelGestionCobro2Layout = new javax.swing.GroupLayout(jPanelGestionCobro2);
        jPanelGestionCobro2.setLayout(jPanelGestionCobro2Layout);
        jPanelGestionCobro2Layout.setHorizontalGroup(
            jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelGestionCobro2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnPatrono)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnDirecciones)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnPagos)
                .addGap(47, 47, 47))
            .addGroup(jPanelGestionCobro2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(jPanelGestionCobro2Layout.createSequentialGroup()
                        .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelGestionCobro2Layout.createSequentialGroup()
                                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbFechaGestion)
                                    .addComponent(lbTipo)
                                    .addComponent(lbGestion)
                                    .addComponent(lbProximaGestion)
                                    .addComponent(lbObservaciones)
                                    .addComponent(lbEnvioCartas)
                                    .addComponent(lbHistorialGestiones))
                                .addGap(18, 18, 18)
                                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(chbEnvioCartas)
                                    .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jScrollPane10)
                                    .addComponent(jScrollPane9)
                                    .addComponent(dcFechaGestion, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(dcFechaProximaGestion, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(cbLocalizado2, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelGestionCobro2Layout.setVerticalGroup(
            jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelGestionCobro2Layout.createSequentialGroup()
                .addComponent(cbLocalizado2)
                .addGap(8, 8, 8)
                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbFechaGestion)
                    .addComponent(dcFechaGestion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbTipo)
                    .addComponent(cbTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbGestion)
                    .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(dcFechaProximaGestion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbProximaGestion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbObservaciones)
                    .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelGestionCobro2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(lbEnvioCartas))
                    .addGroup(jPanelGestionCobro2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chbEnvioCartas)))
                .addGap(10, 10, 10)
                .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnPatrono)
                    .addGroup(jPanelGestionCobro2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnDirecciones)
                        .addComponent(btnPagos)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lbHistorialGestiones)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        btnGuardar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/src/imagenes/btn_guardar.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/src/imagenes/btn_cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 431, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(89, 89, 89)
                        .addComponent(btnGuardar)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancelar)))
                .addGap(18, 18, 18)
                .addComponent(jPanelGestionCobro2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 435, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jPanelGestionCobro2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(60, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void cargarDeuda(){
    
        txtCedula.setText(Long.toString(deuda.getDeudor().getId_Deudor()));
        txtNombre.setText(deuda.getDeudor().getNombre());
        String tel = "";
        for(int i=0; i<vTelefonos.size(); i++){
            BigDecimal numTel = new BigDecimal(vTelefonos.get(i).getTEL());
            tel += String.valueOf(numTel)+", ";            
        }
        txtaTelefonos.setText(tel);
        txtOperacion.setText(Integer.toString(deuda.getId_Deuda()));
        txtDiasMora.setText(Integer.toString(deuda.getDias_Mora()));
        txtCapital.setText("₡ "+Double.toString(deuda.getCapital_Adeudado()));
        txtCouta.setText("₡ "+Double.toString(deuda.getCuota()));
        txtSaldo.setText("₡ "+Double.toString(deuda.getSaldo_Colones()));
        txtTotalAdeudado.setText("₡ "+Double.toString(deuda.getTotal_Adeudado_Colones()));
        txtPagoMinimo.setText("₡ "+Double.toString(deuda.getPago_Minimo_Colones()));
        txtUltimoPago.setText(deuda.getFecha_Ultimo_Pago());
        txtProximoPago.setText(deuda.getFecha_Proximo_Pago());
        txtMontoPagado.setText("₡ "+Double.toString(deuda.getMonto_Pago()));
        txtTipoProducto.setText(deuda.getProducto());
//        txtEmail;     
//        txtTelLocalizado;
//        txtTelefono;   
//        txtaTelefonos;
    
    }
    
    private void cargarTbPromesas(){ // Metodo para cargar las promesas de una deuda
    
        DefaultTableModel modelo = new DefaultTableModel();
        modelo.addColumn("Fecha");
        modelo.addColumn("Monto");
        modelo.addColumn("Periodo");
        tbPromesas.setModel(modelo);
        try{
                Comando comando = new Comando("SELECT * FROM tb_promesa WHERE Id_Deuda = '"+ deuda.getId_Deuda() +"'");
                ResultSet rs = comando.ejecutarSQL(conexion); 
                int i = 0;
                while (rs.next())
                { 
//                    if(i==0){
//                      promesa.setId_Promesa(rs.getInt("Id_Promesa"));  
//                      promesa.setId_Deuda(rs.getInt("Id_Deuda"));
//                      promesa.setFecha_Promesa(rs.getDate("Fecha_Promesa").toString());
//                      promesa.setMonto(rs.getDouble("Monto"));
//                      promesa.setPeriodo(rs.getString("Periodo"));
//                      promesa.setIncumplida(rs.getInt("Incumplida"));
//                    }
                    Object [] fila = new Object[3]; 
                    fila[0] = rs.getDate("Fecha_Promesa"); // El primer indice en rs es el 1, no el cero, por eso se suma 1.
                    fila[1] = rs.getDouble("Monto");
                    fila[2] = rs.getString("Periodo");

                    modelo.addRow(fila);
                    i++;
                }
            }catch(Exception ex){
                JOptionPane.showMessageDialog(null, ex.getMessage(), null, JOptionPane.ERROR_MESSAGE);
            }   
        
    
    }
    
    private void cargarTbHistorialGestiones(){
    
        DefaultTableModel modelo = new DefaultTableModel();
        modelo.addColumn("Fecha");
        modelo.addColumn("Gestión");
        tbHistorialGestiones.setModel(modelo);
        try{
                Comando comando = new Comando("SELECT * FROM tb_gestion WHERE Id_Deuda = '"+ deuda.getId_Deuda() +"'");
                ResultSet rs = comando.ejecutarSQL(conexion); 
                int i = 1;
                while (rs.next())
                {
       // Se crea un array que será una de las filas de la tabla.
                Object [] fila = new Object[2]; 
                Vgestiones.add(rs.getObject(i));
       // Se rellena cada posición del array con una de las columnas de la tabla en base de datos.
                //for (int i=0;i<2;i++){
                    fila[0] = rs.getDate("Fecha_Gestion"); // El primer indice en rs es el 1, no el cero, por eso se suma 1.
                    fila[1] = rs.getString("Descripcion");
                //}
       // Se añade al modelo la fila completa.
                modelo.addRow(fila);
                i++;
                }
            }catch(Exception ex){
                JOptionPane.showMessageDialog(null, ex.getMessage(), null, JOptionPane.ERROR_MESSAGE);
            }   
        
    }
    
    private void txtOperacionPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtOperacionPropertyChange
        txtOperacion.setHorizontalAlignment(4);       
    }//GEN-LAST:event_txtOperacionPropertyChange

    private void txtDiasMoraPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtDiasMoraPropertyChange
        txtDiasMora.setHorizontalAlignment(4);         
    }//GEN-LAST:event_txtDiasMoraPropertyChange

    private void txtCapitalPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtCapitalPropertyChange
        txtCapital.setHorizontalAlignment(4);    
    }//GEN-LAST:event_txtCapitalPropertyChange

    private void txtCoutaPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtCoutaPropertyChange
        txtCouta.setHorizontalAlignment(4);       
    }//GEN-LAST:event_txtCoutaPropertyChange

    private void txtSaldoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtSaldoPropertyChange
        txtSaldo.setHorizontalAlignment(4);       
    }//GEN-LAST:event_txtSaldoPropertyChange

    private void txtTotalAdeudadoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtTotalAdeudadoPropertyChange
        txtTotalAdeudado.setHorizontalAlignment(4);      
    }//GEN-LAST:event_txtTotalAdeudadoPropertyChange

    private void txtPagoMinimoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtPagoMinimoPropertyChange
        txtPagoMinimo.setHorizontalAlignment(4);         
    }//GEN-LAST:event_txtPagoMinimoPropertyChange

    private void txtUltimoPagoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtUltimoPagoPropertyChange
        txtUltimoPago.setHorizontalAlignment(4);       
    }//GEN-LAST:event_txtUltimoPagoPropertyChange

    private void txtProximoPagoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtProximoPagoPropertyChange
        txtProximoPago.setHorizontalAlignment(4);        
    }//GEN-LAST:event_txtProximoPagoPropertyChange

    private void txtMontoPagadoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtMontoPagadoPropertyChange
        txtMontoPagado.setHorizontalAlignment(4);        
    }//GEN-LAST:event_txtMontoPagadoPropertyChange

    private void txtTipoProductoPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtTipoProductoPropertyChange
        txtTipoProducto.setHorizontalAlignment(4);       
    }//GEN-LAST:event_txtTipoProductoPropertyChange

    private void guardarGestion(){
    
        try{ 
                guardarPromesa(); //Metodo para guardar una promesa
                String FechaGestion = new SimpleDateFormat("yyyy/MM/dd").format(dcFechaGestion.getDate());  //Se convierte el JDateChooser a String para poder guardarlo en el formato correcto en la base de datos
                String FechaProximaGestion = new SimpleDateFormat("yyyy/MM/dd").format(dcFechaProximaGestion.getDate()); //Se convierte el JDateChooser a String para poder guardarlo en el formato correcto en la base de datos
                Comando comando = new Comando();
                comando.setConsulta("INSERT INTO `sicgsadb`.`tb_gestion` (`Id_Deuda`, `Fecha_Gestion`, `Tipo`, `Descripcion`, `Fecha_Proxima_Gestion`, `Observaciones`) VALUES ('"+ txtOperacion.getText() +"', '"+ FechaGestion +"', '"+ (String)cbTipo.getSelectedItem() +"', '"+ txtArGestion.getText() +"', '"+ FechaProximaGestion +"', '"+ txtArObservaciones.getText() +"')");
                if(comando.updateSQL(conexion)){
                    JOptionPane.showMessageDialog(this, "La gestión se ingresó exitosamente", "Información", JOptionPane.INFORMATION_MESSAGE);
                    this.dispose(); 
                }
                
            }catch(Exception ex){
                JOptionPane.showMessageDialog(null, ex.getMessage(), null, JOptionPane.ERROR_MESSAGE);
                //System.out.println(ex.getMessage());
            }
    
    }
    
    private void guardarPromesa(){
    
        if(dcFechaPromesa.getDate() != null || !txtMontoPromesa.getText().isEmpty()){// Si alguno de estos campos NO esta vacio, se agrega la promesa
                //AQUI VA LA VALIDACION DE LA PROMESA, HAY QUE VERIFICAR QUE NINGUNO DE LOS CAMPOS ESTE VACIO, ANTES DE INSERTAR LA PROMESA
                //Inserta la promesa
                try{
                    String Periodo = getPeriodo(btngPeriodo); // Variable para guardar el periodo seleccionado de la promesa
                    String FechaPromesa = new SimpleDateFormat("yyyy/MM/dd").format(dcFechaPromesa.getDate());// Convierte el formato de la fecha del JDate 
                    Comando comando = new Comando();                
                    comando.setConsulta("INSERT INTO `sicgsadb`.`tb_promesa` (`Id_Deuda`, `Fecha_Promesa`, `Monto`, `Periodo`) VALUES ('"+ txtOperacion.getText() +"', '"+ FechaPromesa +"', '"+ txtMontoPromesa.getText() +"', '"+ Periodo +"')");
                    comando.updateSQL(conexion);

                }catch(Exception ex){
                    JOptionPane.showMessageDialog(null, ex.getMessage(), null, JOptionPane.ERROR_MESSAGE);
                }            
        }    
    }
    
    public String getPeriodo(ButtonGroup buttonGroup) { // Este metodo devuelve el texto del radiobutton seleccionado
        for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements();) {
            AbstractButton button = buttons.nextElement();

            if (button.isSelected()) {
                return button.getText();
            }
        }

        return null;
    }
    
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        guardarGestion(); //Metodo para guardar la gestion de la deuda
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed

        int i =JOptionPane.showConfirmDialog(this,"¿Realmente desea Salir?","Confirmar Salida",JOptionPane.YES_NO_OPTION);
        if(i==0){ // Si el usuario selecciona la opcion "Si", se sale del from actual y vuelve a la pantalla anterior
            this.dispose(); 
        }
                    
    }//GEN-LAST:event_btnCancelarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnDirecciones;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnPagos;
    private javax.swing.JButton btnPatrono;
    private javax.swing.ButtonGroup btngPeriodo;
    private javax.swing.JCheckBox cbLocalizado2;
    private javax.swing.JComboBox cbTipo;
    private javax.swing.JCheckBox chbEnvioCartas;
    private com.toedter.calendar.JDateChooser dcFechaGestion;
    private com.toedter.calendar.JDateChooser dcFechaPromesa;
    private com.toedter.calendar.JDateChooser dcFechaProximaGestion;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanelDetalleDeuda;
    private javax.swing.JPanel jPanelDeudor;
    private javax.swing.JPanel jPanelGestionCobro2;
    private javax.swing.JPanel jPanelPromesaPago;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lbCapital;
    private javax.swing.JLabel lbCedula;
    private javax.swing.JLabel lbCuota;
    private javax.swing.JLabel lbDiasMora;
    private javax.swing.JLabel lbEmail;
    private javax.swing.JLabel lbEnvioCartas;
    private javax.swing.JLabel lbFechaGestion;
    private javax.swing.JLabel lbFechaPromesa;
    private javax.swing.JLabel lbGestion;
    private javax.swing.JLabel lbHistorialGestiones;
    private javax.swing.JLabel lbMontoPagado;
    private javax.swing.JLabel lbMontoPromesa;
    private javax.swing.JLabel lbNombre;
    private javax.swing.JLabel lbNumeroOperacion;
    private javax.swing.JLabel lbObservaciones;
    private javax.swing.JLabel lbPagoMinimo;
    private javax.swing.JLabel lbProximaGestion;
    private javax.swing.JLabel lbProximoPago;
    private javax.swing.JLabel lbSaldo;
    private javax.swing.JLabel lbTelLocalizado;
    private javax.swing.JLabel lbTelefono;
    private javax.swing.JLabel lbTelefonos;
    private javax.swing.JLabel lbTipo;
    private javax.swing.JLabel lbTipoProducto;
    private javax.swing.JLabel lbTotalAdeudado;
    private javax.swing.JLabel lbUltimoPago;
    private javax.swing.JRadioButton rbMensual;
    private javax.swing.JRadioButton rbQuincenal;
    private javax.swing.JRadioButton rbSemanal;
    private javax.swing.JTable tbHistorialGestiones;
    private javax.swing.JTable tbPromesas;
    private javax.swing.JTextArea txtArGestion;
    private javax.swing.JTextArea txtArObservaciones;
    private javax.swing.JTextField txtCapital;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtCouta;
    private javax.swing.JTextField txtDiasMora;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtMontoPagado;
    private javax.swing.JTextField txtMontoPromesa;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtOperacion;
    private javax.swing.JTextField txtPagoMinimo;
    private javax.swing.JTextField txtProximoPago;
    private javax.swing.JTextField txtSaldo;
    private javax.swing.JTextField txtTelLocalizado;
    private javax.swing.JTextField txtTelefono;
    private javax.swing.JTextField txtTipoProducto;
    private javax.swing.JTextField txtTotalAdeudado;
    private javax.swing.JTextField txtUltimoPago;
    private javax.swing.JTextArea txtaTelefonos;
    // End of variables declaration//GEN-END:variables
}
